package the.workshop.tms.order.infrastructure.commons;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 送货状态
 */
@AllArgsConstructor
@Getter
public enum DeliveryStatusEnum {

    SPONSORED(1, "已发起");

    private final int code;
    private final String name;

    private static final Map<String, DeliveryStatusEnum> CACHE_MAP = Stream.of(values()).collect(Collectors.toMap(DeliveryStatusEnum::getName, it -> it, (a, b) -> b));

    public static Integer getCode(String name) {
        DeliveryStatusEnum it = CACHE_MAP.get(name);
        if (it == null) {
            return null;
        }
        return it.getCode();
    }
}
